/*********************************************************************************
Organization 					: 				Georgia Institute of Technology
  
Institute 						:				Cognitive Computing Group(CCL)
 
Authors							: 				Santiago Ontanon, Kinshuk Mishra
 												Neha Sugandh 
 												
Class							:				ResearchGoal
 
Function						: 				Provides a class for holding the research goal
****************************************************************************/
package planninglanguage.goals;

import org.jdom.Element;

import planninglanguage.conditions.Condition;
import planninglanguage.conditions.ResearchCondition;
import planninglanguage.softconditions.ResearchSoftCondition;
import planninglanguage.softconditions.SoftCondition;
import util.XMLWriter;
import base.WargusGameState;

public class ResearchGoal extends Goal implements Cloneable{

	String m_research;
	int m_playerID;
	
	public ResearchGoal(String a_research,int a_playerID) {
		m_research = a_research;
		m_playerID = a_playerID;
	}
	
	public Condition generateSuccessCondition(WargusGameState a_gamestate)
	{
		return new ResearchCondition(m_research,m_playerID);
	}
	
	public SoftCondition generateSuccessSoftCondition(WargusGameState a_gamestate)
	{
		return new ResearchSoftCondition(m_research,m_playerID);
	}	
	
	public Object clone()
	{
		return new ResearchGoal(m_research,m_playerID);
	}
	
	public float distance(Goal a_g) {
		if (!(a_g instanceof ResearchGoal)) return 1;
		
		ResearchGoal g = (ResearchGoal) a_g;
		float d_r = 1;

		if (m_research.equals(g.m_research)) d_r = 0;
			
		return d_r*0.5f;
	}	
	
	public void writeXML(XMLWriter w) {
		w.tag(Goal.openTag + " " + Goal.XMLtype + "=\"" + 
				this.getClass().getSimpleName() + "\"");
		{
			w.tag(Goal.XMLplayerID, m_playerID);
			w.tag("research", m_research);
		}
		w.tag(Goal.closeTag);
	}	
	protected static ResearchGoal loadFromXML(Element e) {
		int playerID = Integer.parseInt(e.getChildText(XMLplayerID));
		String research = e.getChildText("research");
		return new ResearchGoal(research, playerID);
	}
}
